package com.corpgovernment.job.dao.entity.db;

import com.corpgovernment.job.service.batchimportjob.BatchImportJobExcel;
import com.corpgovernment.job.controller.vo.job.CreateJobReqVo;
import com.corpgovernment.job.controller.vo.job.UpdateJobReqVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
import java.util.Map;

/**
 * @author ldma
 * @date 2024/1/3
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "mb_job")
public class JobDo {

    @Id
    @GeneratedValue(generator = "JDBC")
    private Long id;
    private String name;
    private String code;
    private Long jobTypeId;
    private Boolean deleted;
    private Date createTime;
    private Date updateTime;

    public JobDo(CreateJobReqVo requestParam) {
        this.name = requestParam.getJobName();
        this.code = requestParam.getJobCode();
        this.jobTypeId = requestParam.getJobTypeId();
    }

    public JobDo(UpdateJobReqVo requestParam) {
        this.id = requestParam.getJobId();
        this.name = requestParam.getJobName();
        this.code = requestParam.getJobCode();
        this.jobTypeId = requestParam.getJobTypeId();
    }

    public JobDo(BatchImportJobExcel batchImportJobExcel, Map<String, Long> jobTypeMap) {
        this.name = batchImportJobExcel.getJobName();
        this.code = batchImportJobExcel.getJobCode();
        this.jobTypeId = jobTypeMap.get(batchImportJobExcel.getJobTypeName());
        this.deleted = false;
        this.createTime = new Date();
        this.updateTime = new Date();
    }

}
